#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPainter>
#include <QTimer>
#include <QMouseEvent>
#include <vector>

const int cellSize = 10;
const int rows = 50;
const int cols = 50;

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow() override;

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;

private slots:
    void nextGeneration();

private:
    Ui::MainWindow *ui;
    QWidget *centralWidget;
    QTimer *timer;
    std::vector<std::vector<bool>> cells{rows, std::vector<bool>(cols, false)}; // 使用初始化列表

    int countNeighbors(int row, int col) const;


};
#endif // MAINWINDOW_H
